package com.zsck.zsgy.http

import com.zsck.zsgy.base.BaseResponse
import com.zsck.zsgy.util.AppConstants
import io.reactivex.observers.DisposableObserver
import java.lang.RuntimeException

abstract class ApiSubcribe<T> : DisposableObserver<BaseResponse<T>>() {


    override fun onComplete() {

    }

    override fun onStart() {
        super.onStart()
    }

    /**
     * 处理非API异常
     */
    override fun onError(e: Throwable) {

    }

    /*失败
    * */
    abstract fun onFailure(e: Throwable?, errorMsg: String?)

    override fun onNext(t: BaseResponse<T>) {
        TODO("Not yet implemented")
        val baseResponse: BaseResponse<T> = t as BaseResponse
        if(AppConstants.SUCCESS_CODE.equals(t.code)){
            onSuccess(baseResponse)
        }else{
//            onFailure(RuntimeException(baseResponse.code.toString(),baseResponse.message))
        }
    }

    /*成功*/
    abstract fun onSuccess(t: BaseResponse<T>)



}